package com.hq.ims.data.vo;

import com.hq.authority.utils.AppUtils;
import com.hq.ims.data.config.verification.VdAdd;
import com.hq.ims.data.config.verification.VdEdit;
import com.hq.ims.data.entity.CompanyDepartment;
import com.hq.ims.data.entity.Dict;
import com.hq.ims.data.vo.auth.BaseRowAuthVo;
import com.hq.utils.util.ListUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @author 蒋柏平
 * @since 20240927
 */
@Mapper
public interface DictMapstruct {

    DictMapstruct INSTANCE = Mappers.getMapper(DictMapstruct.class);

    //-------------------------------- 转换VO类 --------------------------------

    @Mappings({
    })
    DictVo toDictVo(Dict source);

    default List<DictVo> toDictVoList(List<Dict> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toDictVo).collect(Collectors.toList());
    }

    @Mappings({
    })
    DictTreeVo toDictTreeVo(Dict source);

    default List<DictTreeVo> toDictTreeVoList(List<Dict> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toDictTreeVo).collect(Collectors.toList());
    }

    //-------------------------------- 以下为自定义类[输出对象] --------------------------------

    @ApiModel(value = "原始对象的扩展类")
    @Data
    class DictVo extends Dict {

    }

    @ApiModel(value = "原始对象的扩展类")
    @Data
    class DictTreeVo extends Dict {

        @ApiModelProperty(value = "子节点")
        private List<DictTreeVo> childrenList = new ArrayList<>();

    }

    @ApiModel(value = "行级权限对象")
    @Data
    class CompanyDepartmentRowAuthVo extends BaseRowAuthVo {

        //自定义其它行级权限


        //构造函数
        public CompanyDepartmentRowAuthVo(CompanyDepartment entity) {
            //当前操作用户ID
            String userId = AppUtils.getUserId();
        }

    }


    //-------------------------------- 以下为自定义类[输入对象] --------------------------------

    @ApiModel(value = "搜索VO")
    @Data
    class PageSearchVo {


    }

    @ApiModel(value = "添加和修改对象")
    @Data
    class SaveVo {

        @NotBlank(message = "字典ID", groups = {VdEdit.class})
        @ApiModelProperty(value = "字典ID")
        private String dictId;

        @NotBlank(message = "字典名称", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "字典名称")
        private String name;

        @NotBlank(message = "父ID", groups = {VdEdit.class})
        @ApiModelProperty(value = "父ID")
        private String parentId;

        @ApiModelProperty(value = "公司ID")
        private String remark;

        @NotNull(message = "排序", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "公司ID")
        private Integer rankNum;

        @ApiModelProperty(value = "额外存储参数")
        private String param;


    }

    //-------------------------------- springboot验证标识 --------------------------------

}
